<?
class Normalization
{
  public $type;
  public $story;
  public $application;
 
  public function __construct() { }
  
  public function smiles($text) {
	
	//detects positive smiles like: :) , :))),  :D , :DDD , :* , :** , 
//	$pattern = "/\:(\)|d|\*)+/i";
	$pattern = "/((\:(\)|d|\*)+)|(xd)|(\<3))/i";
	
	$result = $this -> removeSmiles($text, $pattern);
	
	$text = $result[0];
	$num_of_pos_smile = $result[1]; 
	
	//detects negative smiles like: :( , :((((,  :O , :OOOO , :S , :SSS , 
//	$pattern = "/\:(\(|o|s)+/i";
	$pattern = "/((\:(\(|o|s)+)|(\:\'\())/i";
	
	$result = $this -> removeSmiles($text, $pattern);

	$text = $result[0];
	$num_of_neg_smile = $result[1]; 
	
	return array($text, $num_of_pos_smile, $num_of_neg_smile); 
;
  }

  public function removeSmiles($text, $pattern) {

	$posSmiles = preg_match_all($pattern, $text, $matches);

	$posSmiles_count = count($matches[0]);
	
	$a = $matches[0];		
	usort($a, array($this,"cmp"));
	
	$ordered = array();
	foreach ($a as $key)
		array_push($ordered, $key);
	
	$text = str_replace($ordered, '', $text);
    
	return array($text, count($matches[0]));
  }

  public static function cmp($a, $b)
  {
  	if (strlen($a) == strlen($b)) {
		return 0;
    }
  	return (strlen($a) < strlen($b)) ? 1 : -1;
  }

	
  public function getSentences($text) {
	
	$pattern = "/(\.+|\!+|\?+\;+\:+/";
	
//	preg_match_all();
	
	  
  }
	
	
}

?>